<template>
  <div id="app">
    <layout-common>
      <router-view />
    </layout-common>
  </div>
</template>

<script>
  import common from "@/layout/common";
  import {
    getToken
  } from "@/utils/auth";
  import {
    loginByWechat
  } from "@/api/login";

  export default {
    name: "App",
    components: {
      "layout-common": common
    },
    computed: {
      isRoutesAdded() {
        return this.$store.state.router.isRemoteRoutesAdded;
      }
    },
    methods: {
      getTokenAndLogin() {
        // 1.获取本地token
        let token = getToken();

        // 2. 如果本地没有token不做处理。
        if (!token || token == "null") {
          return false;
        }

        // 3.如果本地有token,则通过token获取用户信息并登录

        this.$store.dispatch("GetUserInfo", token);
      },
      thirdPartyLogin() {
        let searchURL = window.location.search;
        if (searchURL) {
          searchURL = searchURL.substring(1, searchURL.length);
          let code = searchURL.split("&")[0].split("=")[1];
          let state = searchURL.split("&")[1].split("=")[1];
          console.log("code", code, "state", state);
          if (state === "wechat") {
            // 调用第三方登陆的接口
            this.$store.dispatch("LoginByWechat", code);
          }
        }
      }
    },
    mounted() {
      this.getTokenAndLogin();
      this.thirdPartyLogin();
    }
  };

</script>

<style>
  #app {
    min-height: 100%;
  }

  [class*="xui-text-truncate-line"] {
    box-orient: vertical;
  }

  .xui-text-truncate-line-2,
  .xui-text-truncate-line-3,
  .xui-text-truncate-line-4,
  .xui-text-truncate-line-5 {
    display: -webkit-box;
    /* autoprefixer: off /
  -webkit-box-orient: vertical;
  / autoprefixer: on */
  }

  [class*="xui-text-truncate-line"] {
    display: -webkit-box;
    /* autoprefixer: off /
  -webkit-box-orient: vertical;
  / autoprefixer: on */
  }

  .xui-text-truncate-line-2,
  .xui-text-truncate-line-3,
  .xui-text-truncate-line-4,
  .xui-text-truncate-line-5 {
    box-orient: vertical;
  }

</style>
